package cn.classyex.business.hr.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import cn.classyex.business.hr.domain.Candidate;
import cn.classyex.business.hr.service.ICandidateService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 候选人管理Controller
 * 
 * @author yex
 * @date 2021-05-05
 */
@Controller
@RequestMapping("/hr/candidate")
public class CandidateController extends BaseController
{
    private String prefix = "hr/candidate";

    @Autowired
    private ICandidateService candidateService;

    @RequiresPermissions("hr:candidate:view")
    @GetMapping()
    public String candidate()
    {
        return prefix + "/candidate";
    }

    /**
     * 查询候选人管理列表
     */
    @RequiresPermissions("hr:candidate:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Candidate candidate)
    {
        startPage();
        List<Candidate> list = candidateService.selectCandidateList(candidate);
        return getDataTable(list);
    }

    /**
     * 导出候选人管理列表
     */
    @RequiresPermissions("hr:candidate:export")
    @Log(title = "候选人管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Candidate candidate)
    {
        List<Candidate> list = candidateService.selectCandidateList(candidate);
        ExcelUtil<Candidate> util = new ExcelUtil<Candidate>(Candidate.class);
        return util.exportExcel(list, "候选人管理数据");
    }

    /**
     * 新增候选人管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存候选人管理
     */
    @RequiresPermissions("hr:candidate:add")
    @Log(title = "候选人管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Candidate candidate)
    {
        return toAjax(candidateService.insertCandidate(candidate));
    }

    /**
     * 修改候选人管理
     */
    @GetMapping("/edit/{candidateId}")
    public String edit(@PathVariable("candidateId") Long candidateId, ModelMap mmap)
    {
        Candidate candidate = candidateService.selectCandidateById(candidateId);
        mmap.put("candidate", candidate);
        return prefix + "/edit";
    }

    /**
     * 修改保存候选人管理
     */
    @RequiresPermissions("hr:candidate:edit")
    @Log(title = "候选人管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Candidate candidate)
    {
        return toAjax(candidateService.updateCandidate(candidate));
    }

    /**
     * 删除候选人管理
     */
    @RequiresPermissions("hr:candidate:remove")
    @Log(title = "候选人管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(candidateService.deleteCandidateByIds(ids));
    }
}
